#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <string.h>
#include <QDebug>
#include "ad_value.h"

AD_value::AD_value()
{
    AdDevice_Path = "/dev/adc";
    if((fd_adc = open(AdDevice_Path.c_str(), O_RDWR|O_NOCTTY|O_NDELAY))<0)
	{
        qDebug("open adc fail!");
        status = false;
	}
    else status = true;
}

int AD_value::adc_read()
{
    if(status)
    {
        memset(adc_buffer, 0, sizeof(adc_buffer));
        adc_Value = 0;
        read(fd_adc,adc_buffer,10);
        adc_Value = atoi(adc_buffer)*10000/ 4095;
        return adc_Value;
    }
    else return -1;
}
